package com.it.controller;

import com.it.bean.MasterRepplayBean;
import com.it.bean.RepplyBean;
import com.it.bean.UserBasicBean;
import com.it.service.MasterRepplyService;
import com.it.service.RepplyService;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

public class RepplyController {
    public RepplyService repplyService;
    public MasterRepplyService masterRepplyService;


    /**
     * 添加回复
     *
     * @param request
     * @return
     */
    public String addReply(HttpServletRequest request) throws Exception {
        String topicId = request.getParameter("topicId");
        String content = request.getParameter("content");
        RepplyBean repplyBean = new RepplyBean();
        repplyBean.setTopicId(Integer.parseInt(topicId));
        repplyBean.setContent(content);
        repplyBean.setRepplyDate(new Date());
        UserBasicBean userBasicBean = (UserBasicBean) request.getSession().getAttribute("userBasicBean");
        repplyBean.setUid(userBasicBean.getId());
        repplyService.addRepply(repplyBean);
        return "topic.do?operate=getTopicDetail&topicId=" + topicId;
    }

    /**
     * 添加主人回复
     *
     * @param request
     * @return
     * @throws Exception
     */
    public String addMasterReply(HttpServletRequest request) throws Exception {
        String topicId = request.getParameter("topicId");
        String content = request.getParameter("content");
        //回复ID
        String repplyId = request.getParameter("repplyId");
        String uid = request.getParameter("uid");
        MasterRepplayBean masterRepplayBean = new MasterRepplayBean();
        masterRepplayBean.setContent(content);
        masterRepplayBean.setUid(Integer.parseInt(uid));
        masterRepplayBean.setRepplyId(Integer.parseInt(repplyId));
        masterRepplyService.addMasterRepply(masterRepplayBean);
        return "topic.do?operate=getTopicDetail&topicId=" + topicId;
    }


}
